package balgey;
import java.util.Scanner;
public class Demo {
	public static void main(String[] args) {
		/*
		 * 1.注册 2.登录 3.幸运抽奖
		 */
		Scanner input = new Scanner(System.in);
		String answer = "";
		String userName = "";
		String passWord = "";
		int cardNumber=0;
		int max = 9999;
		int min = 1000;
		boolean isRegister = false;
		boolean isLogin = false;
		int [] lucky = new int[5];
		do {
			System.out.println("*****欢迎进入奖客富翁系统*****");
			System.out.println("\t1.注册");
			System.out.println("\t2.登录");
			System.out.println("\t3.抽奖");
			System.out.println("***************************");
			System.out.print("请选择菜单：");
			int choice = input.nextInt();
			switch (choice) {
			case 1:
				System.out.println("[奖客富翁系统 > 注册]");
				System.out.println("请填写个人信息:");
				System.out.print("客户名：");
				userName = input.next();
				System.out.print("密码：");
				passWord = input.next();
				cardNumber = (int) (Math.random() * (max - min)) + min;
				System.out.println("注册成功，请记好您的会员卡号");
				isRegister = true;
				System.out.println("用户名\t密码\t会员卡号");
				System.out.println(userName + "\t" + passWord + "\t" + cardNumber);

				break;
			case 2:
				if (isRegister) {
					for (int i = 0; i < 3; i++) {
						System.out.println("[奖客富翁系统 > 登录]");
						System.out.print("请输入用户名:");
						String user = input.next();
						System.out.print("请输入用密码:");
						String pwd = input.next();
						if (user.equals(userName) && pwd.equals(passWord)) {
							System.out.println("欢迎您:" + user);
							isLogin = true;
							break;
						} else {
							// 1 2 0
							// 2 1 1
							// 3 0 2
							System.out.println("密码错误，您还有" + (2 - i) + "次机会。");
							if (2 - i == 0) {
								break;
							}
						}
					}
				} else {
					System.out.println("请先注册。");
				}
				break;
			case 3:
				if (isLogin) {
					System.out.println("[奖客富翁系统 > 抽奖]");
					System.out.println("请输入您的卡号："+cardNumber);
					for(int i=0; i<5;i++){
						lucky[i] = (int) (Math.random() * (max - min)) + min;
					}
					System.out.print("本日幸运数字为：");
					boolean isLucky= false;
					for(int i=0; i<5;i++){
						 System.out.print(lucky[i] +"\t");
						 if(cardNumber == lucky[i]){
							 isLucky=true;
						 }
					}
					if(isLucky){
						System.out.println("\n恭喜你，你是本日的幸运会员。");
					}else{
						System.out.println("\n抱歉，你不是本日的幸运会员。");
					}
				}else{
					System.out.println("请先登录。");
				}
				break;
			default:
				System.out.println("[您的输入有误！]");
				break;
			}
			System.out.print("继续吗？(y/n)");
			answer = input.next();
		} while (answer.equals("y"));
		System.out.println("系统退出，谢谢使用！");
	}
}
